package com.projectm.common.to;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.io.Serializable;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author linyanbin
 * @date 2022/8/11 21:38
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@ApiModel(value="PhotoLimit对象", description="")
@Component
public class PhotoLimit implements Serializable {

    private static final long serialVersionUID = 1L;

    @Value("${mproject.photo.max-size:-1}")
    @ApiModelProperty(value = "图片最大限制")
    private String maxSize;


    /**
     * 获取图片限制的整数值
     * @Param []
     * @return java.lang.Integer
     **/
    public Integer getPhotoMaxSize() {
        String regEx="[A-Za-z]";
        Pattern pattern = Pattern.compile(regEx);
        Matcher matcher = pattern.matcher(maxSize);
        return Integer.parseInt(matcher.replaceAll("").trim());
    }

    /**
     * 获取图片限制的单位
     * @Param []
     * @return java.lang.String
     **/
    public String getUnit() {
        String regEx="[^A-Za-z]";
        Pattern pattern = Pattern.compile(regEx);
        Matcher matcher = pattern.matcher(maxSize);
        return matcher.replaceAll("").trim();
    }

}
